package com.lhy.vip.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lhy.vip.domain.ApplyMoney;
import com.lhy.vip.service.ApplyMoneyService;
import com.lhy.vip.mapper.ApplyMoneyMapper;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;


import java.util.List;

/**
* @author lhy
* @description 针对表【apply_money】的数据库操作Service实现
* @createDate 2024-07-29 16:49:53
*/
@Service
public class ApplyMoneyServiceImpl implements ApplyMoneyService{
    @Autowired
    private ApplyMoneyMapper iApplyMoneyMapper;

    @Override
    public List<ApplyMoney> selectAll() {
        LambdaQueryWrapper <ApplyMoney> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ApplyMoney::getIsDelete,0);
        return iApplyMoneyMapper.selectList(lqw);
    }


    @Override
    public List<ApplyMoney> selectList(ApplyMoney iApplyMoney) {
        LambdaQueryWrapper <ApplyMoney> lqw = this.lqw(iApplyMoney);
        return iApplyMoneyMapper.selectList(lqw);
    }

    @Override
    public Integer insert(ApplyMoney iApplyMoney) {
        return iApplyMoneyMapper.insert(iApplyMoney);
    }

    @Override
    @Transactional
    public Integer delete(String ids) {
        try {
            String[] split = ids.split(",");
            for (String id : split) {
                ApplyMoney iApplyMoney = new ApplyMoney();
                iApplyMoney.setId(Long.parseLong(id));
                iApplyMoney.setIsDelete(1);
                iApplyMoneyMapper.updateById(iApplyMoney);
            }
            return 1;
        }catch (Exception e){
            return -1;
        }
    }

    @Override
    public Integer update(ApplyMoney iApplyMoney) {
        return iApplyMoneyMapper.updateById(iApplyMoney);
    }

    @Override
    public Page<ApplyMoney> pageAll(Integer page, Integer size) {
        PageHelper.startPage(page,size);
        return (Page<ApplyMoney>)this.selectAll();
    }

    @Override
    public Page<ApplyMoney> pageList(ApplyMoney iApplyMoney, Integer page, Integer size) {
        PageHelper.startPage(page,size);
        return (Page<ApplyMoney>)this.selectList(iApplyMoney);
    }

    public LambdaQueryWrapper lqw(ApplyMoney iApplyMoney){
        LambdaQueryWrapper <ApplyMoney> lqw = new LambdaQueryWrapper<>();
        if (iApplyMoney.getId() != null){
            lqw.eq(ApplyMoney::getId,iApplyMoney.getId());
        }
        if (iApplyMoney.getApplyNum() != null){
            lqw.eq(ApplyMoney::getApplyNum,iApplyMoney.getApplyNum());
        }
        if (iApplyMoney.getVipName() != null){
            lqw.eq(ApplyMoney::getVipName,iApplyMoney.getVipName());
        }
        if (iApplyMoney.getMoney() != null){
            lqw.eq(ApplyMoney::getMoney,iApplyMoney.getMoney());
        }
        if (iApplyMoney.getStatus() != null){
            lqw.eq(ApplyMoney::getStatus,iApplyMoney.getStatus());
        }
        if (iApplyMoney.getApplyTime() != null){
            lqw.eq(ApplyMoney::getApplyTime,iApplyMoney.getApplyTime());
        }
        if (iApplyMoney.getCheckTime() != null){
            lqw.eq(ApplyMoney::getCheckTime,iApplyMoney.getCheckTime());
        }
        return lqw;
    }
}




